package com.g17.virtualpetbackend.repo;

import com.g17.virtualpetbackend.entity.Test;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TestRepository extends Neo4jRepository<Test, Long> {

    @Query("CREATE (t:Test {question: $question, choice1: $choice1, choice2: $choice2, choice3: $choice3, " +
            "choice4: $choice4, ans: $answer, point: $point}) " +
            "RETURN t")
    Test createTest(String question, String choice1, String choice2, String choice3,
                    String choice4, String answer, Float point);

    @Query("MATCH (t:Test) WHERE id(t) = $id " +
            "SET t = {question: $question, choice1: $choice1, choice2: $choice2, " +
            "choice3: $choice3, choice4: $choice4, ans: $answer, point: $point} " +
            "RETURN t")
    Test updateTest(Long id, String question, String choice1, String choice2, String choice3,
                    String choice4, String answer, String point);

    @Query("MATCH (t:Test) WHERE id(t) = $id " +
            "DETACH DELETE t " +
            "RETURN t")
    void deleteTestById(Long id);

    @Query("MATCH (t:Test) WHERE id(t) = $id " +
            "RETURN t")
    Test getTestById(Long id);

    @Query("MATCH (p:Paper)-[i:INCLUDE]->(t:Test) " +
            "WHERE id(p) = $paperId " +
            "RETURN t")
    List<Test> findTestByPaperId(Long paperId);
}
